﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Hosting;

namespace ICeFramework.Web.Common
{
    public class FileUtil
    {
        public static string MapPath(string path)
        {
            string appDomainAppPath;
            //Error.AssertString(path, "path", true);
            if ((path.Length == 0) || (path.IndexOf("://") >= 0))
            {
                return path;
            }
            int num = path.IndexOfAny(new char[] { '\\', '/' });
            if ((num >= 0) && (path[num] == '\\'))
            {
                return path.Replace('/', '\\');
            }
            path = path.Replace('\\', '/');
            HttpServerUtility server = WebUtil.GetServer();
            if (server != null)
            {
                return server.MapPath(path);
            }
            if (path[0] != '/')
            {
                return path;
            }
            appDomainAppPath = HttpRuntime.AppDomainAppPath;
            return MakePath(appDomainAppPath, path.Replace('/', '\\'), '\\');
        }

        public static string MakePath(string part1, string part2, char separator)
        {
            if ((part1 == null) || (part1.Length == 0))
            {
                return (part2 ?? string.Empty);
            }
            if ((part2 == null) || (part2.Length == 0))
            {
                return part1;
            }
            bool flag = part1[part1.Length - 1] == separator;
            bool flag2 = part2[0] == separator;
            if (flag && flag2)
            {
                return (part1 + part2.Substring(1));
            }
            if (!flag && !flag2)
            {
                return (part1 + separator + part2);
            }
            return (part1 + part2);
        }
    }
}
